class FriendsWin extends Scene{
    private closeImage:eui.Image;
    private moreFriendsImage:eui.Image;
    private datalistRank:any  = [];
    private ListDataAdd:any  = [];//添加好友数组
    private addFriendScroller:eui.Scroller;
    private needright: boolean = false;  //好友添加是否滑倒最右边
    private manageFriendsImage:eui.Image;
    private friendsRankList:eui.List;
    private addFriendslist:eui.List;
    public delayScroll: number = 250;//添加好友滚动条滚动时间
    private isFrist:number=0;//是否为初始数据
    
    public constructor() {
        super();
        this.addEventListener(egret.Event.COMPLETE, this.addToStage, this);
        this.addEventListener(egret.Event.COMPLETE, this.addToStageRank, this);
        
      }
    
      public onSkinLoaded() {
        this.closeImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
        this.moreFriendsImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
        this.manageFriendsImage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnHandler, this);
      }

      private btnHandler(evt: egret.TouchEvent) {
        let btnFocused = evt.currentTarget;        
		    switch (btnFocused) {
          case this.closeImage:
            SceneManager.instance.removeScene(this);
            break;
          case this.moreFriendsImage:
            this.moveFriend();
            break;
          case this.manageFriendsImage:
              SceneManager.instance.addScene(new ManageFriend());
              break;
        }
      }

      private addToStageRank():void{
        for(var i:number=1;i<=4;i++){
          if(i==1)
          {
            this.datalistRank.push({rank:i,name:"南华大学好友"+i,length:"100cm"+i,rankColor:"0xEA0903"});
          }
          else if(i==2)
          {
            this.datalistRank.push({rank:i,name:"南华大学好友"+i,length:"100cm"+i,rankColor:"0xf26508"});
          }
          else if(i==3)
          {
            this.datalistRank.push({rank:i,name:"南华大学好友"+i,length:"100cm"+i,rankColor:"0xeebf2b"});
          }
          else
          {
            this.datalistRank.push({rank:i,name:"南华大学好友"+i,length:"100cm"+i,rankColor:"0x0f2540"});
          }
          if(this.isFrist==1)
        {
          var tw1 = egret.Tween.get( this.addFriendScroller.viewport );
          tw1.to( {x:this.addFriendScroller.viewport.x+696}, this.delayScroll);
        }
        }
        this.friendsRankList.dataProvider=new eui.ArrayCollection(this.datalistRank);
        this.friendsRankList.itemRenderer=FriendsRankRenderer;
      }
      private moveFriend():void{
        for(var i:number=1;i<=4;i++){
          this.datalistRank.push({rank:i,name:"南华大学好友"+i,length:"100cm"+i,rankColor:"0x0f2540"});
        }
        this.friendsRankList.dataProvider=new eui.ArrayCollection(this.datalistRank);
        this.friendsRankList.itemRenderer=FriendsRankRenderer;
      }

      private addToStage():void{
        for(var i:number=1;i<=1;i++){
          this.ListDataAdd.push({name:"南华大学好友",name1:"南华大学好友",name2:"南华大学好友",head:"resource/assets/FriendsWin/大圆.png",head1:"resource/assets/FriendsWin/大圆.png",head2:"resource/assets/FriendsWin/大圆.png"});
        }
        if(this.isFrist==1)
        {
          var tw1 = egret.Tween.get( this.addFriendScroller.viewport );
          tw1.to( {x:this.addFriendScroller.viewport.x+696}, this.delayScroll);
        }
        var tlayout:eui.TileLayout=new eui.TileLayout;
        tlayout.horizontalGap=18;
        tlayout.requestedRowCount=1;
        this.addFriendslist.layout=tlayout;
        this.addFriendslist.dataProvider=new eui.ArrayCollection(this.ListDataAdd);
        this.addFriendslist.itemRenderer=AddFriendRenderer;
        this.addFriendScroller.addEventListener(eui.UIEvent.CHANGE, this.moveHandler, this);
	    	this.addFriendScroller.addEventListener(eui.UIEvent.CHANGE_END, this.outHandler, this);
      }


      private moveHandler(evt: eui.UIEvent): void {
        if(this.addFriendScroller.viewport.scrollH  > (this.addFriendScroller.viewport.contentWidth - this.addFriendScroller.viewport.width)+70){
          this.needright = true;
         }
      }
      private outHandler(evt:eui.UIEvent):void{
        if(this.needright){
          this.needright = false;
          this.addToStage();
          //this.addFriendScroller.viewport.scrollH=this.addFriendScroller.viewport.scrollH+696;
          this.isFrist=1;
        }
      }


}